package com.yike.product.controller;

import com.yike.product.entity.GoodsSupplier;
import com.yike.product.param.GoodsSupplierParam;
import com.yike.product.service.GoodsSupplierService;
import com.yike.product.vo.GoodsSupplierVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.product.param.GoodsSupplierPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品供应商 控制器
 *
 * @author Sakura
 * @since 2024-10-21
 */
@Slf4j
@RestController
@RequestMapping("/platform/goodsSupplier")
@Module("product")
@Api(value = "商品供应商API", tags = {"平台商品供应商"})
public class GoodsSupplierController extends BaseController {

    @Autowired
    private GoodsSupplierService goodsSupplierService;

    /**
     * 添加商品供应商
     */
    @PostMapping("/add")
    @OperationLog(name = "添加商品供应商", type = OperationLogType.ADD)
    @ApiOperation(value = "添加商品供应商", response = ApiResult.class)
    public ApiResult<Boolean> addGoodsSupplier(@Validated(Add.class) @RequestBody GoodsSupplierParam goodsSupplierParam) throws Exception {
        boolean flag = goodsSupplierService.saveGoodsSupplier(goodsSupplierParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改商品供应商
     */
    @PostMapping("/update")
    @OperationLog(name = "修改商品供应商", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改商品供应商", response = ApiResult.class)
    public ApiResult<Boolean> updateGoodsSupplier(@Validated(Update.class) @RequestBody GoodsSupplierParam goodsSupplierParam) throws Exception {
        boolean flag = goodsSupplierService.updateGoodsSupplier(goodsSupplierParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除商品供应商
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除商品供应商", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除商品供应商", response = ApiResult.class)
    public ApiResult<Boolean> deleteGoodsSupplier(@PathVariable("id") Long id) throws Exception {
        boolean flag = goodsSupplierService.deleteGoodsSupplier(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取商品供应商详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "商品供应商详情", type = OperationLogType.INFO)
    @ApiOperation(value = "商品供应商详情", response = GoodsSupplierVo.class)
    public ApiResult<GoodsSupplierVo> getGoodsSupplier(@PathVariable("id") Long id) throws Exception {
        GoodsSupplierVo goodsSupplierVo = goodsSupplierService.getGoodsSupplier(id);
        return ApiResult.ok(goodsSupplierVo);
    }

    /**
     * 商品供应商分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "商品供应商分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "商品供应商分页列表", response = GoodsSupplierVo.class)
    public ApiResult<Paging<GoodsSupplierVo>> getGoodsSupplierPageList(@Validated @RequestBody GoodsSupplierPageParam goodsSupplierPageParam) throws Exception {
        Paging<GoodsSupplierVo> paging = goodsSupplierService.getGoodsSupplierPageList(goodsSupplierPageParam);
        return ApiResult.ok(paging);
    }

}

